home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / GameKit / gamekit-1 / BonusTracker.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  77 lines

  1.  
  2. #import <gamekit/gamekit.h>
  3. #import <ansi/math.h>
  4.  
  5. #define PUTINBOUNDS if (value < min) value = min; \
  6.                     if (value > max) value = max
  7.                     
  8. @implementation BonusTracker
  9.  
  10. - init
  11. {
  12.     [super init];
  13.     min = 0;
  14.     increment = 0;
  15.     multiplier = 1;
  16.     baseValue = 0;
  17.     max = MAXINT;
  18.     [self resetBonus];
  19.     return self;
  20. }
  21.  
  22. - (int)bonusValue
  23. {
  24.     return value;
  25. }
  26.  
  27. - setBaseValue:(int)newValue
  28. {
  29.     baseValue = newValue;
  30.     return self;
  31. }
  32.  
  33. - setMultiplier:(int)newMultiplier
  34. {
  35.     multiplier = newMultiplier;
  36.     return self;
  37. }
  38.  
  39. - setIncrement:(int)newIncrement
  40. {
  41.     increment = newIncrement;
  42.     return self;
  43. }
  44.  
  45. - setMin:(int)newMin max:(int)newMax
  46. {
  47.     min = newMin; max = newMax;
  48.     PUTINBOUNDS;
  49.     return self;
  50. }
  51.  
  52. - resetBonus
  53. {
  54.     value = baseValue;
  55.     return self;
  56. }
  57.  
  58. - advanceBonus // move to the next bonus value.
  59. {
  60.     value *= multiplier;
  61.     value += increment;
  62.     PUTINBOUNDS;
  63.     return self;
  64. }
  65.  
  66. - retreatBonus // inverse of above method.
  67. {
  68.     value -= increment;
  69.     // avoid divide by zero...
  70.     if (multiplier) value /= multiplier;
  71.     PUTINBOUNDS;
  72.     return self;
  73. }
  74.  
  75.  
  76. @end
  77.